<?php
/**
 * 商品控制器
 */
Class GoodsAction extends CommonAction {

	/**
	 * 商品列表模版
	 */
	Public function index () {
		import('ORG.Util.Page');
		$db = M('goods');
		//计算分页
		$count = $db->count('id');
		$page = new Page($count, 10);
		$limit = $page->firstRow . ',' . $page->listRows;
		$result = $db->limit($limit)->select();

		//分配置变量
		$this->brand = $result;
		$this->page = $page->show();
		$this->display();
	}

	/**
	 * 添加商品页
	 */
	Public function addGoods () {
		$this->display();
	}

	/**
	 * 添加商品操作
	 */
	Public function runAddGoods () {
		import('ORG.Net.UploadFile');
		$upload = new UploadFile();// 实例化上传类
		$upload->maxSize  = 3145728 ;// 设置附件上传大小
		$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->savePath =  './Upload/';// 设置附件上传目录
		if(!$upload->upload()) {// 上传错误提示错误信息
		   $this->error($upload->getErrorMsg());
		}else{// 上传成功 获取上传文件信息
		   $info =  $upload->getUploadFileInfo();
		   $path = $info[0]['savepath'].$info[0]['savename'];
		   $data = array(
				'name' => $this->_post('name'),
				'url' => $this->_post('url'),
				'desc' => $this->_post('desc'),
				'hot' => $this->_post('hot'),
				'logo' => $path
			);
			if (M('goods')->data($data)->add()) {
				$this->success('添加成功', U('index'));
			} else {
				$this->error('添加失败');
			}
		}
		// p($_POST);
		// p($path);die;
		
	}

	
}
?>